<template>
    <div :class="{ hidden: hidden }" class="pagination-container">
        <el-pagination
            samll
            :background="background"
            :current-page="pageObj.pageNum"
            :page-size="pageObj.pageSize"
            :layout="layout"
            :page-sizes="pageSizes"
            :total="total"
            v-bind="$attrs"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
        />
    <!-- v-bind="$attrs": 将调用组件时的组件标签上绑定的非props的特性(class和style除外)向下传递。
    在子组件中应当添加 inheritAttrs: false(避免父作用域的不被认作props的特性绑定应用在子组件的根元素上)。
    https://zhuanlan.zhihu.com/p/195455758    -->
    </div>
</template>
<script>
export default {
    name: 'Pagination',
    props: {
        total: {
            required: true,
            type: Number,
            default: 0
        },
        pageObj: {
            type: Object,
            default: () => {}
        },
        pageSizes: {
            type: Array,
            default: () => [10, 20, 50, 100]
        },
        layout: {
            type: String,
            default: 'total, sizes, prev, pager, next, jumper'
        },
        background: {
            type: Boolean,
            default: true
        },
        hidden: {
            type: Boolean,
            default: false
        }
    },
    emits: ['handleSizeChange', 'handleCurrentChange'],
    setup (props, { emit }) {
        const handleSizeChange = (val) => {
            emit('handleSizeChange', val)
        }
        const handleCurrentChange = (val) => {
            emit('handleCurrentChange', val)
        }
        return {
            handleSizeChange,
            handleCurrentChange
        }
    }
}
</script>
